package io.renren.modules.contract.controller;

import java.util.List;
import java.util.Map;

import io.renren.common.utils.DateUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.contract.entity.ContractReceiptInfoEntity;
import io.renren.modules.contract.service.ContractReceiptInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 收款明细表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-12-13 11:37:57
 */
@RestController
@RequestMapping("/contract/contractreceiptinfo")
public class ContractReceiptInfoController {
	@Autowired
	private ContractReceiptInfoService contractReceiptInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ContractReceiptInfoEntity> contractReceiptInfoList = contractReceiptInfoService.queryList(query);
		int total = contractReceiptInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(contractReceiptInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("contract:contractreceiptinfo:info")
	public R info(@PathVariable("id") Long id){
		ContractReceiptInfoEntity contractReceiptInfo = contractReceiptInfoService.queryObject(id);
		
		return R.ok().put("contractReceiptInfo", contractReceiptInfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody ContractReceiptInfoEntity contractReceiptInfo){
		if (StringUtils.isNotBlank(contractReceiptInfo.getReceiptDateSrc())){
			contractReceiptInfo.setReceiptDate(DateUtils.strToDate(contractReceiptInfo.getReceiptDateSrc()));
		}
		contractReceiptInfoService.save(contractReceiptInfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("contract:contractreceiptinfo:update")
	public R update(@RequestBody ContractReceiptInfoEntity contractReceiptInfo){
		contractReceiptInfoService.update(contractReceiptInfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Map<String, Object> params){
		contractReceiptInfoService.delete(Long.valueOf((String) params.get("id")));
		return R.ok();
	}
	
}
